from gradio_client import Client, handle_file, file
from django_redis import get_redis_connection
import threading
import time
import pymysql


class xryuntts(threading.Thread):
    rds = get_redis_connection("sysconf")

    def __init__(self):
        threading.Thread.__init__(self)
        self.isRun = True

    def stop(self):
        self.isRun = False

    def run(self):
        print("开始stts任务")
        while self.isRun:
            time.sleep(1)
            task = self.getTask()
            if not task:
                continue
        print("stts任务结束")

    def getTask(self):
        """查询一个任务"""
        # 检测数据
        if self.rds.llen("audio"):
            return self.rds.lpop("audio")
        else:
            return None


if __name__ == "__main__":
    print("hello")
    dostts = xryuntts()
    dostts.start()
    dostts.join()
    while True:
        cmd = input(">")
        if cmd in ["q", "e", "quit", "exit"]:
            break
    print("bye")
